<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/laytpl/template.js"></script>
<script src="/res/common/js/jquery.form.js"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script type="text/javascript" src="/res/third/nice-validator/jquery.validator.js?local=zh-CN"></script>
<script type="text/javascript">
	function deleteRow(id){
		art.dialog.confirm("确定删除？",function(){
			art.dialog.post({
				url:"/level/config/delete.do", data:{id: id}, success:function(data){
					if(data.success){
                        window.location.reload();
					}
				}
				
			})
		},function(){
			
		})
	}
	function editRow(id) {
        $.getJSON('/level/config/get.do', { id: id}, function (data, textStatus, jqXHR) {
            addRow(data.obj);
        });
    }
    function addRow(data) {
	    if (!data) { data = {}; }
	    var content = template("edit_template", data);
        dialog = art.dialog({
            title: "新增等级规则",
            lock: true,
            content: content,
            okVal: "提交",
            ok: function () {
                var levelName = $("input[name='levelName']").val();
                if ($.trim(levelName).length == 0) {
                    alert("请填写等级名称");
                    return false;
                }
                var levelCode = $("input[name='levelCode']").val();
                if ($.trim(levelCode).length == 0) {
                    alert("请填写等级编码");
                    return false;
                }
                var levelValue = $("input[name='levelValue']").val();
                if ($.trim(levelValue).length == 0) {
                    alert("请填写等级最低值");
                    return false;
                }
                var subData = $("#edit_form").serialize();
                art.dialog.post({ url:"/level/config/save.do", data: subData, success:function(data){
                        if(data.success){
                            window.location.reload();
                        }
                    } 
                });
            }
        });
    }
    var picDialog;
    function uploadPic() {
        picDialog = art.dialog.uploadFile("上传商品图",
            {callback: "uploadPicCallBack", userpath:"admin", extensions:"gif,jpg,png,jepg,bmp"});
    }
    function uploadPicCallBack(response) {
        // response.url
		picDialog.close();
        $("#imgLevelIcon").attr("src", response.url);
        $("input[name='levelIcon']").val(response.url);
    }
</script>
<script type="text/html" id="edit_template">
	<form id="edit_form" action="/level/config/save.do" method="post" class="form-horizontal" role="form">
		<input type="hidden" name="id" value="{{id}}">
		<input type="hidden" name="levelType" value="${levelType}">
		<div class="form-group">
			<label  class="col-sm-4 control-label">名称</label>
			<div class="col-sm-6">
				<input type="text" class="form-control" placeholder="请输入名称" name="levelName" value="{{levelName}}">
			</div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">编码</label>
			<div class="col-sm-6">
				<input type="text" class="form-control" placeholder="请输入编码" name="levelCode" value="{{levelCode}}">
			</div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">等级图标</label>
			<div class="col-sm-6">
                <img style="width: 40px;height: 30px;" id="imgLevelIcon" onclick="uploadPic();" src="{{if levelIcon}}{{levelIcon}}{{else}}/res/common/images/img.png{{/if}}"/>
				<input type="hidden" name="levelIcon" value="{{levelIcon}}">
			</div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">等级最低值</label>
			<div class="col-sm-6">
				<input type="text" class="form-control" placeholder="请输入等级最低值" name="levelValue" value="{{levelValue}}">
			</div>
		</div>
	</form>
</script>
</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<span class="input-group-btn">
				<button class="btn btn-default" type="button" onclick="addRow()">新增</button>
			</span>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
				<tr>
					<th>#</th>
					<th>等级名称</th>
					<th>等级代码</th>
					<th>等级图标</th>
					<th>等级最低值</th>
					<th>创建时间</th>
					<th>更新时间</th>
					<th>操作</th>
				</tr>
			[#list list as item ]
			<tr>
				<td align="center">${item_index+1}</td>
				<td align="center">${item.levelName!}</td>
				<td align="center">${item.levelCode!}</td>
				<td align="center">[#if item.levelIcon??]<img style="width: 40px;height: 30px;" src="${item.levelIcon!}"/>[/#if]</td>
				<td align="center">${item.levelValue!}</td>
				<td align="center">${item.createtime?string("yyyy-MM-dd HH:mm:ss")!}</td>
				<td align="center">${item.updatetime?string("yyyy-MM-dd HH:mm:ss")!}</td>
				<td align="center">
					<button type="button" onclick="editRow('${item.id}')"  class="btn btn-info btn-xs">编辑</button>
					<button type="button"  onclick="deleteRow(${item.id})"  class="btn btn-default btn-xs delbtn">删除</button>
				</td>
			</tr>
			[/#list]
		</table>
	</div>
</body>
</html>
